from driver import GPIO


relay_1 = GPIO()

relay_2 = GPIO()


def init():
    relay_1.open("RELAY1")
    relay_2.open("RELAY2")
    relay_ctl(1, 1)


def relay_ctl(port, state):
    if port == 1:
        relay_1.write(state)
        print("[RELAY] relay port1,state={}".format(relay_1.read()))
    elif port == 2:
        relay_2.write(state)
        print("[RELAY] relay port2,state={}".format(relay_2.read()))

    elif port == 3:
        relay_1.write(state)
        relay_2.write(state)
        print("[RELAY] relay port1&port2,state={}-{}".format(relay_1.read(), relay_2.read()))


def get_relay_state(port):
    if port == 1:
        return relay_1.read()
    elif port == 2:
        return relay_2.read()
    elif port == 3:
        return relay_1.read(), relay_2.read()
